package com.cn.topAndFoot.service.impl;

import com.cn.common.pojo.ResultModel;
import com.cn.common.pojo.TopModel;
import com.cn.topAndFoot.mapper.TopDao;
import com.cn.topAndFoot.service.TopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TopServiceImpl implements TopService {
    @Autowired
    TopDao topDao;
    @Override
    public ResultModel top() {
        return ResultModel.getResultModel("success",0,1,topDao.top());
    }

    @Override
    public ResultModel delete(int id) {
        return ResultModel.getResultModelByCount(topDao.delete(id));
    }

    @Override
    public ResultModel update(TopModel topModel) {
        return ResultModel.getResultModelByCount(topDao.update(topModel));
    }

    @Override
    public ResultModel insert(TopModel topModel) {
        return ResultModel.getResultModelByCount(topDao.insert(topModel));
    }

    @Override
    public ResultModel enable(int id) {
        return ResultModel.getResultModelByCount(topDao.enable(id));
    }

    @Override
    public ResultModel findById(int id) {
        return ResultModel.getResultModelByAll(topDao.findById(id),1);
    }

    @Override
    public ResultModel limit(TopModel topModel) {
        return ResultModel.getResultModel("",0,1,topDao.limit(topModel));
    }

    @Override
    public ResultModel findAll(int limit,int page) {
        PageHelper.startPage(limit,page);
        List<TopModel> all = topDao.findAll();
        PageInfo<TopModel> topModelPageInfo = new PageInfo<>(all);
        return ResultModel.getResultModel("",0,(int) topModelPageInfo.getTotal(),topModelPageInfo.getList());
    }

}
